/* GUI CONVERTED from rprsiq02.p (converter v1.75) Mon Oct 23 21:04:56 2000 */
/* rprsiq02.p - RESOURCE LOAD DETAIL INQUIRY                            */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*K17J*/
/*V8:ConvertMode=Report                                        */
/* REVISION: 1.0     LAST MODIFIED: 06/12/86    BY: pml                 */
/* REVISION: 4.0     LAST MODIFIED: 12/30/87    BY: wug *A137*          */
/* REVISION: 2.0     LAST MODIFIED: 01/06/88    BY: pml *A125*          */
/* REVISION: 4.0     LAST MODIFIED: 03/23/88    BY: rl  *A171*          */
/* REVISION: 5.0     LAST MODIFIED: 05/03/89    BY: wug *B098*          */
/* REVISION: 4.0     LAST MODIFIED: 06/20/89    BY: emb *A748*          */
/* REVISION: 5.0     LAST MODIFIED: 12/07/89    BY: ftb *B422*          */
/* REVISION: 5.0     LAST MODIFIED: 02/22/90    BY: wug *B582*          */
/* REVISION: 4.0     LAST MODIFIED: 02/22/90    BY: wug *D017*          */
/* REVISION: 5.0     LAST MODIFIED: 04/04/90    BY: ram *B640*          */
/* REVISION: 6.0     LAST MODIFIED: 04/10/90    BY: ram *D018*          */
/* REVISION: 5.0     LAST MODIFIED: 06/08/90    BY: ram *B705*          */
/* REVISION: 5.0     LAST MODIFIED: 09/27/90    BY: ram *B793*          */
/* REVISION: 6.0     LAST MODIFIED: 02/14/91    BY: ram *D351*          */
/* REVISION: 7.0     LAST MODIFIED: 10/11/91    BY: emb *F024*          */
/* REVISION: 7.3     LAST MODIFIED: 10/23/92    BY: ram *G231*          */
/* Revision: 7.3        Last edit: 11/19/92             By: jcd *G339* */
/* REVISION: 7.3     LAST MODIFIED: 09/06/94    BY: jxz *FP82*          */
/* REVISION: 8.6     LAST MODIFIED: 11/04/97    BY: bvm *K17J*          */
/* REVISION: 8.6     LAST MODIFIED: 12/13/97    BY: *H0QB*  Russ Witt   */

/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb              */
/* REVISION: 9.1      LAST MODIFIED: 10/23/00   BY: *N0T0* Katie Hilbert    */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

/*K17J*/ {mfdtitle.i "b+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rprsiq02_p_1 "Per Col"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/*FP82*/ define new shared variable site like si_site.
/*FP82*/ define new shared variable start like rq_start.
     define variable start1 like rq_start.
/*FP82*/ define new shared variable rscde like rq_rsc.
/*H0QB**FP82* define new shared variable dwm as character format "!"
                                                          label "D/W/M".   */
/*N0T0* /*H0QB*/ define new shared variable dwm as character format "!"  */
/*N0T0*/ define new shared variable dwm as character format "!(1)"
                                                          label "D/W/M/P".
/*FP82*/ define new shared variable idays as integer
/*H0QB*                format ">>>>>9" label "Per Column".  */
/*H0QB*/               format ">>>>>9" label {&rprsiq02_p_1}.

     define new shared variable vq_-ratio as integer extent 7 no-undo.
     define new shared variable vq_-title as character no-undo.
     define new shared variable vq_-period as date extent 14 no-undo.
     define new shared variable vq_-bar-color as character no-undo.

/*FP82*/ define new shared variable dev1 like prd_dev.
/*FP82*/ define new shared variable path1 like prd_path.
/*N0T0***********BEGIN DELETE OF UNUSED LOCAL VARIABLES
 * define variable rscde1 like rq_rsc.
 * define variable interval as integer extent 8.
 * define variable sdate like rq_start extent 8.
 * define variable load as decimal extent 8 format "->>>,>>9".
 * define variable cap as decimal extent 8 format "->>>,>>9".
 * define variable ovund as decimal extent 8 format "->>>,>>9".
 * define variable cum as decimal extent 8 format "->>>,>>9".
 * define variable workdays as integer extent 8 format ">>>>,>>9".
 * define variable det_load as decimal extent 8 format "->>>,>>9".
 * define variable holiday as integer.
 * define variable i as integer.
 * define variable j as integer.
 * define variable qty like rq_qty.
 * define variable wostart as integer.
 * define variable nonwdays as decimal.
 * define variable elapsedays as integer.
 * define variable wdays as integer.
 * define variable overlap as integer.
 * define variable wointerval as integer.
 * define variable offset like rq_lt_off.
 * define variable ltoff like rq_lt_off.
 * define variable ltoffperiod as integer.
 * define variable lead as integer.
 * define variable num_intervals as integer initial 7.
 * define variable monthend as integer.
 * define variable pge like mfc_logical initial "n".
 * define variable x as integer.
 *N0T0***********END DELETE*/

/*K17J* {mfdtitle.i "b+ "}* *moved up*/

     
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
        site
        rscde
        rs_desc        format "x(18)" no-attr-space no-label
        start
        dwm
        idays
     with frame a no-underline width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



     /* SET EXTERNAL LABELS */
     setFrameLabels(frame a:handle).

     site = global_site.

     view frame a.

/*K17J*/ {wbrp01.i}

         repeat:
        do:
           if start = ? then start = today.
           if dwm = "" then dwm = "W".
           if idays = 0 or idays = ? then idays = 1.

/*K17J*/      if c-application-mode <> 'web' then
              update site rscde start dwm idays with frame a editing:

          if frame-field = "site"  then do:

             /* FIND NEXT/PREVIOUS RECORD */
             {mfnp.i si_mstr site si_site site si_site si_site}

             if recno <> ? then do with frame a:
            site = si_site.
            display site.
             end.
          end.
          else if frame-field = "rscde" then do:
             /* FIND NEXT/PREVIOUS RECORD */
             {mfnp.i rs_mstr rscde rs_rsc rscde rs_rsc rs_rsc}
             if recno <> ? then do:
/*G231*/                site = rs_site.
            rscde = rs_rsc.
/*G231                  display rscde rs_desc with frame a. */
/*G231*/                display site rscde rs_desc with frame a.
             end.
          end.
          else do:
             status input.
             readkey.
             apply lastkey.
          end.
           end.

/*K17J*/ {wbrp06.i &command = update &fields = "  site rscde start dwm idays"
          &frm = "a"}

/*K17J*/ if (c-application-mode <> 'web') or
/*K17J*/ (c-application-mode = 'web' and
/*K17J*/ (c-web-request begins 'data')) then do:

/*G231         find rs_mstr where rs_rsc = rscde no-lock no-error. */
/*G231*/       find rs_mstr where rs_rsc = rscde
/*G231*/       and rs_site = site no-lock no-error.
           if available rs_mstr then display rs_desc with frame a.

           find shop_cal where shop_site = site
           and shop_wkctr = "" and shop_mch = "" no-lock no-error.
           if not available shop_cal then
           find shop_cal where shop_site = ""
           and shop_wkctr = "" and shop_mch = "" no-lock no-error.
           if not available shop_cal then do:
          {mfmsg.i 410 4}
          /* "DEFAULT SHOP CALENDAR DOES NOT EXIST" */
/*K17J*/        if c-application-mode = 'web' then return.
          undo, retry.
           end.

           if start < today then do:
          {mfmsg.i 15 2}
          /* "START DATE IS BEFORE TODAY" */
           end.

           if index("dwmp",dwm) = 0 then do:
/*N0T0*          {mfmsg.i 14 3}      */
            /* INTERVAL MUST BE (D)ay (W)eek (M)onth OR (P)eriod */
/*N0T0*/    {pxmsg.i &MSGNUM=170 &ERRORLEVEL=3}
/*K17J*/        if c-application-mode = 'web' then return.
                   pause.
          undo.
           end.
/*K17J*/     end.
        end.

/*FP82      hide frame b. */
/*FP82      hide frame d. */

        /* SELECT PRINTER */
            {mfselprt.i "terminal" 80}

/*FP82*/    dev1 = dev.
/*FP82*/    path1 = path.

/*FP82********************move following into rsrpiq2a.p ***********************
        /* COMPUTE START DATES */
        sdate[1] = today.
        {mfcsdate.i}

        do i = 1 to num_intervals + 1:
           sdate[i] = max(sdate[i],today).
           if i > 1 then interval[i - 1] = max(sdate[i] - sdate[i - 1],0).
        end.

        /* INITIALIZE VARIABLES */
        cap = 0.
        workdays = 0.
        load = 0.
        ovund = 0.
        cum = 0.

        /* CALCULATE WORKING DAYS IN EACH INTERVAL */
        {mfcwdays.i site}
        do i = 1 to num_intervals + 1:
           workdays[i] = max(workdays[i],0).
        end.

        /* CALCULATE CAPACITY IN EACH INTERVAL */
/*G231      {mfccap.i} */
/*G231*/    {mfccap.i site}

        {mfcsdate.i}
        {mfcwdays.i site}
        workdays[1] = max(workdays[1],0).
        sdate[1] = low_date.

        display
           space(15) "Past    " sdate[2 for 6] skip
           space(15) sdate[2] - 1 sdate[3] - 1 sdate[4] - 1 sdate[5] - 1
           sdate[6] - 1 sdate[7] - 1 sdate[8] - 1 skip
           space(15)
           "-------- -------- -------- -------- -------- -------- --------"
           "Workdays      " workdays[1 for 7] skip
           "Capacity      " cap[1 for 7]
        with frame b width 80 no-labels.

        /* CALCULATE  LOAD IN EACH PERIOD  */
        pause 0 no-message.
        if dev = "terminal" then do:
           {mfmsg.i 401 1}
           /* "CALCULATING LOAD" */
        end.

/*G231      for each shop_cal where shop_wkctr = "" and shop_mch = "" no-lock:*/
/*G231*/    find shop_cal no-lock where shop_site = site
/*G231*/    and shop_wkctr = "" and shop_mch = "" no-error.
/*G231*/    if not available shop_cal then
/*G231*/       find shop_cal no-lock where shop_site = ""
/*G231*/       and shop_wkctr = "" and shop_mch = "" no-error.
/*G231*/    if available shop_cal then do:

/*G231         for each rq_mstr where rq_rsc = rscde no-lock by rq_part: */
/*G231*/       for each rq_mstr where rq_rsc = rscde
/*G231*/       and rq_site = site
/*G231*/       no-lock by rq_part:
                {mfrpchk.i}                     /*G339*/

          for each wo_mstr where wo_part = rq_part
          and (wo_due >= rq_start or rq_start = ?)
          and (wo_due <= rq_end or rq_end = ?)
          and (wo_qty_ord - wo_qty_comp - wo_qty_rjct > 0)
          and wo_status <> "C"
/*G231*/          and wo_site = rq_site
          no-lock by wo_nbr:
                {mfrpchk.i}                     /*G339*/

             /* CALCULATE LOAD INTERVALS FOR A GIVEN WORK ORDER  */
             {mfcload.i}

             /* DISPLAY WORK ORDERS DETAIL */
             display
             " W/O:" wo_nbr "Item:" wo_part skip
             space(15) det_load[1 for 7] skip
             with no-labels width 80.

          end.
           end.
/*G231         leave. */
        end.

        /* DISPLAY LOAD OVER/UNDER AND CUMULATIVE */
        display "Total Load    " load[1 for 7]
        with frame d no-labels width 80.

        do i = 1 to num_intervals + 1:
           ovund[i] = cap[i] - load[i].
           ovund[i] = integer(ovund[i]).
           cum[i] = ovund[i].
           if i > 1 then cum[i] = cum[i] + cum[i - 1].
        end.

        display "Over/Under    " ovund[1 for 7] with frame d no-labels.
        display "Cumulative    " cum[1 for 7] with frame d no-labels.
        pause 0 no-message.

        if path = "terminal" then repeat:
           message "Press space bar to display graph".
           readkey.
           if lastkey = 32 then do:

          do x = 1 to 7:
     /*          load[x] = random(0,200). */
             vq_-period[x] = sdate[x].
             vq_-period[x + 7] = sdate[x + 1] - 1.
             vq_-ratio[x] = load[x] / cap[x] * 100.
          end.

          /* ASSIGN THE COLORS */
          assign vq_-bar-color = if opsys eq "msdos"
                     and terminal eq "co80"
                     then "white/red"
                     else "message".

          /* ASSIGN THE TITLE */
          assign vq_-title = " LOAD % OF CAPACITY ".
          /* NOTE LEADING/TRAILING BLANKS */

          {gprun.i ""gpgraph.p""}
           end.
           else leave.
        end.
*FP82*********************end of the move**************************************/

/*FP82*/    {gprun.i """rprsiq2a.p"""}

        {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

        {mfmsg.i 8 1}
     end.

/*K17J*/ {wbrp04.i &frame-spec = a}
